home *** CD-ROM | disk | FTP | other *** search
- Path: nntp-server.caltech.edu!mika
- From: mika@ariadne.cs.caltech.edu (Mika Nystroem)
- Newsgroups: comp.lang.c
- Subject: longjmp/setjmp madness
- Date: 23 Mar 1996 11:01:15 GMT
- Organization: California Institute of Technology, Pasadena
- Distribution: world
- Message-ID: <4j0llr$rvl@gap.cco.caltech.edu>
- NNTP-Posting-Host: ariadne.cs.caltech.edu
-
-
-
- Hi everyone,
- I have been trying to write a nasty little program here, and had some
- problems. I have managed to distill my problem to the following
- unpleasantness.
- The man pages are a little sketchy on how longjmp and setjmp are supposed
- to work, but I don't *think* I have violated the specification. If I have,
- please correct me on that point. (I know that what this program is doing
- is incredibly nasty, and at least in this case, could be done much
- nicer.. I just want to know if it is written according to specs.)
- This program compiles and executes without problems on
- sparc/SunOS 4.1.4
- AXP/DEC UNIX 3.2
-
- And compiles and executes with a segfault upon leaving p1() on
- i386/NetBSD 1.1A
- i386/Linux 1.3.x
- i386/NeXTstep
- sparc/NetBSD 1.1B
-
- Ho hum.
- Mika
- <mika@vlsi.cs.caltech.edu>
-
- P.S. If you wish to respond to me, please Cc: me in email. Thanks!
-
- --- nasty begins here ---
- /* ltest.c
- mika@vlsi
- */
-
- #include <setjmp.h>
- #include <stdio.h>
-
- jmp_buf e1,e2,e3,e4;
-
- void p1()
- {
- if(!setjmp(e2)) longjmp(e1,1);
- printf("p1 returning now\n"); fflush(stdout);
- return;
- }
-
- void
- main()
- {
- if(!setjmp(e1)) {
- printf("calling p1\n");
- p1();
- printf("returning from p1()\n");
- exit(0);
- }
- printf("longjmping to p1/e2\n");
- longjmp(e2,1);
- }
-
-
-